package alejandro.castro.abstracts;

public abstract class CyclicSceneComponent extends MovableComponent {

	public CyclicSceneComponent(double x, double y) {
		super(x, y);
	}

    @Override
    public void move(double dx, double dy) {
    	super.move(dx, dy);
    	this.correctX();
    	this.correctY();
    }

	private void correctY() {
		if(this.borderBottom() < 0){
			this.setY(this.getGame().getDisplayHeight());
		}
		if(this.borderTop() > this.getGame().getDisplayHeight()){
			this.setY(- getHeight());
		}
		
	}

	private void correctX() {
		if(this.borderRight() < 0){
			this.setX(this.getGame().getDisplayWidth());
		}
		if(this.borderLeft() > this.getGame().getDisplayWidth()){
			this.setX(- getWidth());
		}
		
	}

}
